package com.yonyougov.devops.cruxcisupport.committest;

import com.yonyougov.devops.cruxcisupport.committest.dto.QueryDto;
import com.yonyougov.devops.cruxcisupport.committest.dto.StatisticsCommitTestDto;
import com.yonyougov.devops.cruxcisupport.committest.dto.StatisticsRejectedDto;
import com.yonyougov.devops.cruxcisupport.committest.vo.*;
import com.yonyougov.devops.cruxcisupport.user.UserEntity;
import com.yonyougov.devops.fwc.core.dao.impl.BaseDaoImpl;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;
import java.util.List;

/**
 * 提测表数据层实现
 */
@Repository
public class CommitTestDaoImpl extends BaseDaoImpl<CommitTestEntity, BigInteger> implements CommitTestDao {
    //<!--用户自定义代码开始-->
    private final SqlSessionTemplate sqlSessionTemplate;

    public CommitTestDaoImpl(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }

    /**
     * 根据提测id查询提测单
     *
     * @param commitTestId 提测id
     * @return CommitTestPageLikeRespVo
     * @date @date 2020年3月31日11:23:16
     */
    @Override
    public CommitTestPageLikeRespVo findCommitTestByPrimaryKey(BigInteger commitTestId) {
        String statement = CommitTestEntity.class.getName() + "Mapper.findCommitTestByPrimaryKey";
        return sqlSessionTemplate.selectOne(statement, commitTestId);
    }

    /**
     * 当前用户是开发人员,根据当前用户id获取提测表中的总记录数
     *
     * @param queryListDto com.yonyougov.devops.cruxcisupport.committest.vo.QueryCommitStartPageDto
     * @return int
     */
    @Override
    public int countByDevelop(QueryListDto queryListDto) {
        String statement = CommitTestEntity.class.getName() + "Mapper.countByDevelop";
        return sqlSessionTemplate.selectOne(statement, queryListDto);
    }

    /**
     * 当前用户是开发人员,根据当前用户id获取提测表中的记录
     *
     * @param queryListDto com.yonyougov.devops.cruxcisupport.committest.vo.QueryCommitStartPageDto
     * @return List<CommitTestPageLikeRespVo>
     */
    @Override
    public List<QueryCommitTestVo> findAllByDevelop(QueryListDto queryListDto) {
        String statement = CommitTestEntity.class.getName() + "Mapper.findAllByDevelop";
        return sqlSessionTemplate.selectList(statement, queryListDto);
    }

    /**
     * 当前用户是测试人员,根据当前用户id获取提测表中的总记录数
     *
     * @param queryListDto com.yonyougov.devops.cruxcisupport.committest.vo.QueryCommitStartPageDto
     * @return int
     */
    @Override
    public int countByTest(QueryListDto queryListDto) {
        String statement = CommitTestEntity.class.getName() + "Mapper.countByTest";
        return sqlSessionTemplate.selectOne(statement, queryListDto);
    }

    /**
     * 当前用户是测试人员,根据当前用户id获取提测表中的记录
     *
     * @param queryListDto com.yonyougov.devops.cruxcisupport.committest.vo.QueryCommitStartPageDto
     * @return List<CommitTestPageLikeRespVo>
     */
    @Override
    public List<QueryCommitTestVo> findAllByTest(QueryListDto queryListDto) {
        String statement = CommitTestEntity.class.getName() + "Mapper.findAllByTest";
        return sqlSessionTemplate.selectList(statement, queryListDto);
    }

    /**
     * 管理员角色查询
     *
     * @param commitTestPageLikeParamsVo com.yonyougov.devops.cruxcisupport.committest.vo.QueryCommitStartPageDto
     * @return int
     */
    @Override
    public int countByAdmin(QueryListDto commitTestPageLikeParamsVo) {
        String statement = CommitTestEntity.class.getName() + "Mapper.countByAdmin";
        return sqlSessionTemplate.selectOne(statement, commitTestPageLikeParamsVo);
    }

    /**
     * 管理员角色查询
     *
     * @param commitTestPageLikeParamsVo com.yonyougov.devops.cruxcisupport.committest.vo.QueryCommitStartPageDto
     * @return List<CommitTestPageLikeRespVo>
     */
    @Override
    public List<QueryCommitTestVo> findAllByAdmin(QueryListDto commitTestPageLikeParamsVo) {
        String statement = CommitTestEntity.class.getName() + "Mapper.findAllByAdmin";
        return sqlSessionTemplate.selectList(statement, commitTestPageLikeParamsVo);
    }

    /**
     * 查询测试主管
     * 条件: 提测单id
     *
     * @param commitTestEntity [com.yonyougov.devops.cruxcisupport.committest.CommitTestEntity]
     * @return [com.yonyougov.devops.cruxcisupport.user.UserEntity]
     */
    @Override
    public UserEntity findTestLeadByCommitTestId(CommitTestEntity commitTestEntity) {
        String statement = CommitTestEntity.class.getName() + "Mapper.findTestLeadByCommitTestId";
        return sqlSessionTemplate.selectOne(statement, commitTestEntity);
    }

    /**
     * 今天提测数
     *
     * @return Long
     */
    @Override
    public Long todayCommitTestNumber() {
        String statement = CommitTestEntity.class.getName() + "Mapper.todayCommitTestNumber";
        return sqlSessionTemplate.selectOne(statement);
    }

    /**
     * 统计-提测
     *
     * @param statisticsCommitTestDto com.yonyougov.devops.cruxcisupport.committest.dto.StatisticsCommitTestDto
     * @return java.util.List
     */
    @Override
    public List<StatisticsCommitTestVo> statisticsCommitTest(StatisticsCommitTestDto statisticsCommitTestDto) {
        String statement = CommitTestEntity.class.getName() + "Mapper.statisticsCommitTest";
        return sqlSessionTemplate.selectList(statement, statisticsCommitTestDto);
    }

    /**
     * 统计-提测
     *
     * @param statisticsCommitTestDto com.yonyougov.devops.cruxcisupport.committest.dto.StatisticsCommitTestDto
     * @return java.util.List
     */
    @Override
    public int statisticsCommitTestCount(StatisticsCommitTestDto statisticsCommitTestDto) {
        String statement = CommitTestEntity.class.getName() + "Mapper.statisticsCommitTestCount";
        return sqlSessionTemplate.selectOne(statement, statisticsCommitTestDto);
    }

    /**
     * 统计-驳回
     *
     * @param statisticsRejectedDto com.yonyougov.devops.cruxcisupport.committest.dto.StatisticsRejectedDto
     * @return java.util.List
     */
    @Override
    public List<StatisticsRejectedVo> statisticsRejected(StatisticsRejectedDto statisticsRejectedDto) {
        String statement = CommitTestEntity.class.getName() + "Mapper.statisticsRejected";
        return sqlSessionTemplate.selectList(statement, statisticsRejectedDto);
    }

    /**
     * 统计-驳回
     *
     * @param statisticsRejectedDto com.yonyougov.devops.cruxcisupport.committest.dto.StatisticsRejectedDto
     * @return int
     */
    @Override
    public int statisticsRejectedCount(StatisticsRejectedDto statisticsRejectedDto) {
        String statement = CommitTestEntity.class.getName() + "Mapper.statisticsRejectedCount";
        return sqlSessionTemplate.selectOne(statement, statisticsRejectedDto);
    }

    @Override
    public QueryCommitTestVo queryCommitTest(QueryDto queryCommitTestDto) {
        String statement = CommitTestEntity.class.getName() + "Mapper.queryCommitTest";
        return sqlSessionTemplate.selectOne(statement, queryCommitTestDto);
    }

    //<!--用户自定义代码结束-->
}
